class Solution:
    def waysToSplit(self, nums: list) -> int:
        def search1(sums, target):
            left = 0
            right = len(sums)
            while left < right:
                mid = (left + right) // 2
                if sums[mid] < target:
                    left = mid + 1
                else:
                    right = mid

            return left

        def search2(sums, target):
            left = 0
            right = len(sums)
            while left < right:
                mid = (left + right) // 2
                if target < sums[mid]:
                    right = mid
                else:
                    left = mid + 1

            return left

        sums = [0]
        s = 0
        for num in nums:
            s += num
            sums.append(s)
        ans = 0
        for i in range(1, len(sums)):
            left = search1(sums, sums[i] * 2)
            right = search2(sums, (sums[i] + sums[-1]) // 2)
            left = max(i + 1, left)
            right = min(len(nums), right)
            if left <= right:
                ans += right - left
        return ans % (10**9 + 7)
